package com.yxdj.order.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yxdj.common.core.domain.R;
import com.yxdj.common.core.web.controller.BaseController;
import com.yxdj.common.core.web.domain.AjaxResult;
import com.yxdj.common.core.web.page.TableDataInfo;
import com.yxdj.common.security.annotation.InnerAuth;
import com.yxdj.order.api.domain.OrderInfo;
import com.yxdj.order.service.OrderInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 韩总
 */
@Tag(name = "订单信息管理")
@RestController
@RequestMapping("/order")
public class OrderInfoController extends BaseController {

    @Autowired
    private OrderInfoService orderInfoService;

    @Operation(summary = "分页获取订单列表")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(value = "serviceOptionName", required = false) String serviceOptionName){
        //开启分页
        startPage();
        //带条件的查询
        List<OrderInfo> list = orderInfoService.list(new LambdaQueryWrapper<OrderInfo>().like(serviceOptionName != null, OrderInfo::getServiceOptionName, serviceOptionName));
        return getDataTable(list);
    }

    @Operation(summary = "获取订单详情")
    @GetMapping("/getById/{id}")
    public AjaxResult getById(@PathVariable("id") Long id){
        //根据id获取订单详情
        OrderInfo orderInfo = orderInfoService.getOrderInfoById(id);
        return AjaxResult.success(orderInfo);
    }

    @InnerAuth
    @Operation(summary = "供微服务内部远程调用根据id获取订单信息")
    @GetMapping("/getOrderInfoById/{id}")
    public R<OrderInfo> getOrderInfoById(@PathVariable("id") Long id){
        //根据id获取订单详情
        OrderInfo orderInfo = orderInfoService.getById(id);
        return R.ok(orderInfo);
    }
}
